/*
 * Copyright (c) 2023, 2023,yzc.cn All rights reserved.
 *
 */
package cn.yzc;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>Project: RabbitMQ - RabbitMqConfig</p>
 * <p>Powered by yzc On 2023-12-25 20:23:06</p>
 * <p>描述：<p>
 *
 * @author yzc [yzc0415@126.com]
 * @version 1.0
 * @since 17
 */
@Configuration
public class RabbitMqConfig {
    /**
     * 声明私信队列
     * @return
     */
    @Bean
    public Queue deadQueue(){
        return new Queue("deadQueue");
    }

    /**
     * 声明正常队列
     */
    @Bean
    public Queue normalQueue(){
        return new Queue("normalQueue");
    }

    /**
     * 声明订单队列
     * @return
     */
    @Bean
    public Queue orderQueue(){
        return QueueBuilder.durable("orderQueue")
                .withArgument("x-message-ttl",30000) //消息ttl
                .withArgument("x-dead-letter-exchange","deadExchange") //绑定死信交换器
                .withArgument("x-dead-letter-routing-key","dead") //绑定死信路由键
                .build();
    }

    /**
     * 声明死信交换器
     * @return
     */
    @Bean
   public DirectExchange deadExchange(){
        return new DirectExchange("deadExchange");
   }

    /**
     * 声明正常交换器
     * @return
     */
   @Bean
   public DirectExchange normalExchange(){
        return new DirectExchange("normalExchange");
   }

    /**
     * 声明订单交换器
     * @return
     */
    @Bean
   public DirectExchange orderExchange(){
       return new DirectExchange("orderExchange");
   }

    /**
     * 绑定死信队列和交换器
     * @param deadQueue
     * @param deadExchange
     * @return
     */
   @Bean
   public Binding bindingDead(Queue deadQueue,DirectExchange deadExchange){
        return BindingBuilder.bind(deadQueue).to(deadExchange).with("dead");
   }

    /**
     * 绑定正常队列和交换器
     * @param normalQueue
     * @param normalExchange
     * @return
     */
   @Bean
   public Binding bindingNormal(Queue normalQueue,DirectExchange normalExchange){
       return BindingBuilder.bind(normalQueue).to(normalExchange).with("normal");
   }

    /**
     * 绑定订单队列和交换器
     * @param orderQueue
     * @param orderExchange
     * @return
     */
   @Bean
   public Binding bindingOrder(Queue orderQueue,DirectExchange orderExchange){
        return BindingBuilder.bind(orderQueue).to(orderExchange).with("orders");
   }

}
